package com.shuda.business.channel.controller;

import com.shuda.business.channel.entity.FinancialClue;
import com.shuda.business.channel.service.FinancialClueDbService;
import com.shuda.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/clues")
public class ClueController {
    
    @Autowired
    private FinancialClueDbService financialClueDbService;
    
    @GetMapping
    public Result<List<FinancialClue>> getAllClues() {
        List<FinancialClue> clues = financialClueDbService.getList();
        return Result.success(clues);
    }
    
    @GetMapping("/{id}")
    public Result<FinancialClue> getClueById(@PathVariable Long id) {
        FinancialClue clue = financialClueDbService.getById(id);
        return clue != null ? Result.success(clue) : Result.error("线索不存在");
    }
    
    @PostMapping
    public Result<FinancialClue> createClue(@RequestBody FinancialClue clue) {
        boolean result = financialClueDbService.insert(clue);
        return result ? Result.success(clue) : Result.error("创建线索失败");
    }
    
    @PutMapping("/{id}")
    public Result<FinancialClue> updateClue(@PathVariable Long id, @RequestBody FinancialClue clue) {
        clue.setId(id);
        boolean result = financialClueDbService.update(clue);
        return result ? Result.success(clue) : Result.error("更新线索失败");
    }
    
    @DeleteMapping("/{id}")
    public Result<Void> deleteClue(@PathVariable Long id) {
        boolean result = financialClueDbService.delete(id);
        return result ? Result.success() : Result.error("删除线索失败");
    }
}